<?php
	include_once '../models/Model.php';
	$model=new Model();
	$roomName=$_POST['roomName'];
	$oldRoom=$model->searchRoomByName($roomName);
	$roomId=$oldRoom->getRoomId();
	$roomCost=$_POST['roomCost'];
	$roomSeatCount=$_POST['roomSeatCount'];
	$room=new Room($roomId,$roomCategory,$roomName,$roomCost,$roomSeatCount);
	// update success
	if($model->updateRoomInfo($room)==0){
		$date = date("Y-m-d H:i:s");
		$log = $date."---Event---".$roomId."---ChangeRoomInfo\n";
		$path="../log/log.txt";
		$file=fopen($path, "a");
		$write=fwrite($file,$log);
		fclose($file);
		echo "<script type='text/javascript'>\n";
		echo "alert('Update successful');\n";
		echo "window.location='../view/manager/room_manager.php'";
		echo "</script>";
	}
	else
	{
		echo "<script type='text/javascript'>\n";
		echo "alert('Update fail');\n";
		echo "window.location='../view/manager/room_manager.php'";
		echo "</script>";
	}
?>